import { mergeMap as _observableMergeMap, catchError as _observableCatch } from 'rxjs/operators';
import { Observable, from as _observableFrom, throwError as _observableThrow, of as _observableOf } from 'rxjs';
import { Injectable } from '@angular/core';
import { TodoParams, TodoVm } from './todo-list.define';
import { Client } from 'src/app/app.client';
import { Level } from './todo-list.model';

@Injectable({
    providedIn: 'root'
})
export class TodoClient extends Client {
    url_ = this.getUrl('/todos');

    create(todoParams: TodoParams): Observable<TodoVm> {
      const options_: any = this.getOptions(todoParams);
      return this.request('post', this.url_, options_, TodoVm);
    }

    getall(isCompleted?: boolean | null | undefined, level?: Level[] | null | undefined): Observable<TodoVm[]> {
        let url_ = this.baseUrl + '/todos?';
        if (isCompleted !== undefined) {
            url_ += 'isCompleted=' + encodeURIComponent('' + isCompleted) + '&';
        }
        if (level !== undefined) {
            level.forEach(item => { url_ += 'level=' + encodeURIComponent('' + item) + '&'; });
        }
        const options_: any = this.getOptions();
        return this.request('get', url_, options_, TodoVm);
    }

    update(todoVm: TodoVm): Observable<TodoVm> {
        const options_: any = this.getOptions(todoVm);
        return this.request('put', this.url_, options_, TodoVm);
    }

    delete(id: string): Observable<TodoVm> {
        if (id === undefined || id === null) {
            throw new Error('The parameter \'id\' must be defined.');
        }
        let url_ = this.baseUrl + '/todos/{id}';
        url_ = url_.replace('{id}', encodeURIComponent('' + id));
      const options_: object = this.getOptions();
      return this.request('delete', url_, options_, TodoVm);
    }
}
